import requests

from api.ihrmEmpManageApi import EmpManageApi
from common.assertTools import common_assert


class TestAddEmp(object):

    def setup_class(self):
        self.emp = EmpManageApi()
        resp = requests.post(url=" http://ihrm2-test.itheima.net/api/sys/login",
                                 json={"mobile": "13800000002", "password": "123456"})
        token = resp.json().get("data")
            #
        self.req_header = {"Content-Type": "application/json",
                          "Authorization": token}
    #
    def test01_add_succeess(self):
    #     # 添加员工
    #     emp=EmpManageApi()
    #     resp = requests.post(url=" http://ihrm2-test.itheima.net/api/sys/login",
    #                          json={"mobile": "13800000002", "password": "123456"})
    #     token = resp.json().get("data")
    #     #
    #     req_header = {"Content-Type": "application/json",
    #                   "Authorization": token}
        req_body = {
            "username": "小傻瓜001",
            "mobile": "13912219912",
            "workNumber": "9588"
        }
        resp=self.emp.add_emp(self.req_header,req_body)
        print(resp.json())

        common_assert(resp,200,True,10000,'操作成功')

    def test02_mobile_none(self):
        # 手机号为空
        # def test01_add_succeess(self):
        #     emp = EmpManageApi()
        #     resp = requests.post(url=" http://ihrm2-test.itheima.net/api/sys/login",
        #                          json={"mobile": "13800000002", "password": "123456"})
        #     token = resp.json().get("data")
        #     #
        #     req_header = {"Content-Type": "application/json",
        #                   "Authorization": token}
            req_body = {
                "username": "小傻瓜002",
                "mobile": "None",
                "workNumber": "9588"
            }
            resp = self.emp.add_emp(self.req_header, req_body)
            print(resp.json())

            common_assert(resp, 200, False, 20002, '新增员工失败')
    #
    def test01_no_params(self):
           # 无参
        # emp = EmpManageApi()
        resp = requests.post(url=" http://ihrm2-test.itheima.net/api/sys/login",
                             json={"mobile": "13800000002", "password": "123456"})
        token = resp.json().get("data")
        #
        req_header = {"Content-Type": "application/json",
                      "Authorization": token}
        req_body = None
        resp = self.emp.add_emp(self.req_header, req_body)
        print(resp.json())

        common_assert(resp, 200, False, 99999, '系统繁忙')
